{% extends 'manage/base_manage.html' %}
{% load static %}
{% block title %}Web测试用例列表{% endblock %}
{% block css %}
    <link rel="stylesheet" href="{% static 'css/web_test/web_test_manage.css' %}">
{% endblock %}

{% block content %}
    <div class="content">
        <div id="test_content">
            <div id="test_list">
                <a id="title_distance" href="{% url 'atp:apis_manage' %}">单一接口用例</a>
                <a id="title_distance" href="{% url 'atp:api_test_manage' %}">流程接口用例</a>
                <a id="title_distance" href="{% url 'atp:web_test_manage' %}">Web测试用例</a>
                <a id="title_distance" href="{% url 'atp:app_test_manage' %}">App测试用例</a>
            </div>
            <h3 id="add_test_name">Web用例列表</h3>
            <a id="add_test" href="{% url 'atp:web_test_add' %}">＋添加Web用例</a>
            <div id="test_search">
                <form method="get" action="{% url 'atp:web_test_search' %}">
                    {% csrf_token %}
                    <div class="form-group">
                        <br><br>
                        <input name="web_t_name" type="search" class="form-control"
                               placeholder="输入Web用例名称">
                        <button type="submit" id="search_b" class="btn btn-default">搜索</button>
                    </div>
                </form>
            </div>

            <form id="" method="post" action="">
                {% csrf_token %}
                <table class="table-striped" id="table_list">
                    <thead>
                    <tr id="tr_title">
                        <th id="table_title_length">ID</th>
                        <th id="table_title_length4">产品名称</th>
                        <th id="table_title_length4">Web用例名称</th>
                        <th id="table_title_length4">Web用例描述</th>
                        <th id="table_title_length4">测试负责人</th>
                        <th id="table_title_length4">测试结果</th>
                        <th id="table_title_length3">时间</th>
                        <th id="table_title_length">查看</th>
                        <th id="table_title_length">编辑</th>
                        <th id="table_title_length">删除</th>
                    </tr>
                    </thead>
                    <tbody>
                    {% for web_t in web_tests %}
                        <tr id="tr_d">
                            <td>{{ web_t.id }}</td>
                            <td>{{ web_t.web_t_pro.product_name }}</td>
                            <td>{{ web_t.web_t_name }}</td>
                            <td>{{ web_t.web_t_desc }}</td>
                            <td>{{ web_t.web_ter }}</td>
                            <td>{% if web_t.web_t_res == 0 %}
                                <a style="color: red;text-decoration: none">{{ web_t.web_t_res }}</a>
                            {% elif web_t.web_t_res == 1 %}
                                <a style="color: green;text-decoration: none">{{ web_t.web_t_res }}</a>
                            {% endif %}
                            </td>
                            <td>{{ web_t.create_time }}</td>
                            <td><a href="{% url 'atp:web_step_manage' web_t.id %}"
                                   class="glyphicon glyphicon-ok-sign" id="check_f"></a></td>
                            <td><a style="color:cadetblue "
                                   href="{% url 'atp:web_test_update' web_t.id %}">编辑</a></td>
                            <td><a style="color: #cc0000" href="javascript:"
                                   onclick="confirm_delete({{ web_t.id }})">删除</a></td>
                        </tr>
                    {% endfor %}
                    </tbody>
                </table>
            </form>
            <!--分页-->
            <div id="pager">
                <nav aria-label="Page navigation">
                    <ul class="pagination">

                        {% if web_tests.has_previous %}
                            <li>
                                <a href="?page={{ web_tests.previous_page_number }}&web_t_name={{ search_name }}"
                                   aria-label="Previous">
                                    <span aria-hidden="true">&laquo;</span>
                                </a>
                            </li>

                        {% else %}
                            <li class="disabled">
                                <a href="#" aria-label="Next">
                                    <span aria-hidden="true">&raquo;</span>
                                </a>
                            </li>
                        {% endif %}

                        {% for page_index in web_tests.paginator.page_range %}
                            {% ifequal page_index  web_tests.number %}
                                <li class="active">
                                    <a style="background: cadetblue"
                                       href="?page={{ page_index }}&web_t_name={{ search_name }}">{{ page_index }}</a>
                                </li>
                            {% else %}
                                <li>
                                    <a href="?page={{ page_index }}&web_t_name={{ search_name }}">{{ page_index }}</a>
                                </li>
                            {% endifequal %}

                        {% endfor %}

                        {% if web_tests.has_next %}
                            <li>
                                <a href="?page={{ web_tests.next_page_number }}&web_t_name={{ search_name }}"
                                   aria-label="Next">
                                    <span aria-hidden="true">&raquo;</span>
                                </a>
                            </li>
                        {% else %}
                            <li class="disabled">
                                <a href="#" aria-label="Next">
                                    <span aria-hidden="true">&raquo;</span>
                                </a>
                            </li>
                        {% endif %}

                    </ul>
                </nav>
            </div>
        </div>
    </div>
{% endblock %}

{% block js %}
    <script>

        function confirm_delete(web_t_id) {
            layer.open({
                title: "是否确认删除?",
                btn: ['确定', '取消'],
                yes: function () {
                    $.ajax({
                        url: "{% url 'atp:web_test_delete'  %}",
                        type: "GET",
                        dataType: "JSON",
                        data: {"web_t_id": web_t_id},
                        success: function (res) {
                            if (res.code === 200) {
                                layer.msg('删除成功');
                                setTimeout(function () {
                                    parent.location.reload();
                                }, 1000);
                            } else {
                                layer.msg('删除失败');
                                setTimeout(function () {
                                    parent.location.reload();
                                }, 1000);
                            }
                        }
                    })
                }
            })
        }
    </script>
{% endblock %}